package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.shop.Product;
import com.mvp.shq.washer.entity.shop.result.OrderDetailListRestult;
import com.mvp.shq.washer.utils.DataDictionary;
import com.mvp.shq.washer.utils.ImageUtil;
import com.mvp.shq.washer.utils.StringUtils;

import java.math.BigDecimal;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by westing on 2017/10/11.
 * 支付订单列表
 */

public class OrderPayListAdapter extends RecyclerView.Adapter<OrderPayListAdapter.ViewHolder> {


    private Context context;
    private List<OrderDetailListRestult> productList;
    private ImageUtil imageUtil;
    public List<OrderDetailListRestult> getProductList() {
        return productList;
    }

    public void setProductList(List<OrderDetailListRestult> productList) {
        this.productList = productList;
    }

    public OrderPayListAdapter(Context mContext, List<OrderDetailListRestult> productList) {
        this.context = mContext;
        this.productList=productList;
        imageUtil = new ImageUtil(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_orderlist, parent, false);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        OrderDetailListRestult product= productList.get(position);
        BigDecimal decimal = new BigDecimal("0");
        int type = 0;
        String money1 = "",money2 = "",integral = "";
        money1 = (int)product.getCashPrice()*product.getNum()+"";
        money2 = StringUtils.BigDecimalToStr(BigDecimal.valueOf(product.getCashPrice()*product.getNum()));
        integral = (int)product.getIntegralPrice()*product.getNum()+"";
        //现金加积分购买
        holder.llMoney.setVisibility(View.VISIBLE);
        holder.tvAdd.setVisibility(View.VISIBLE);
        holder.llIntegral.setVisibility(View.VISIBLE);
        holder.tvMoney1.setText(money1);
        holder.tvMoney2.setText(money2);
        if(money1.equals("0")&&money2.equals("0")){
            holder.tvAdd.setVisibility(View.GONE);
            holder.tvMoney1.setVisibility(View.GONE);
            holder.tvMoney2.setVisibility(View.GONE);
        }
        if(integral.equals("0")){
            holder.llIntegral.setVisibility(View.INVISIBLE);
            holder.tvAdd.setVisibility(View.GONE);
        }
        holder.tvIntegral.setText(integral);
        imageUtil.loadUrlImage(product.getProductImg(),holder.imgProductPic);
        holder.tvProductTitle.setText(product.getProductName());
        holder.tvProductType.setText(product.getSpecInfo());

        holder.tvByType.setText(product.getSpecInfo());
        holder.tvBySize.setVisibility(View.GONE);
        holder.tvByNum.setVisibility(View.VISIBLE);
        holder.tvByNum.setText(product.getNum()+"");
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    @Override
    public int getItemCount() {
        return productList!=null?productList.size():0;
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_product_pic)
        ImageView imgProductPic;//商品图片
        @BindView(R.id.tv_product_title)
        TextView tvProductTitle;//商品标题
        @BindView(R.id.tv_product_type)
        TextView tvProductType;//商品类型
        @BindView(R.id.tv_by_type)
        TextView tvByType;//香型
        @BindView(R.id.tv_by_size)
        TextView tvBySize;//规格
        @BindView(R.id.tv_money_1)
        TextView tvMoney1;//价格：元
        @BindView(R.id.tv_money2)
        TextView tvMoney2;//价格：角分
        @BindView(R.id.ll_money)
        LinearLayout llMoney;
        @BindView(R.id.tv_add)
        TextView tvAdd;
        @BindView(R.id.tv_integral)
        TextView tvIntegral;//积分
        @BindView(R.id.ll_integral)
        LinearLayout llIntegral;
        @BindView(R.id.tv_by_num)
        TextView tvByNum;//数量
        @BindView(R.id.tv_jifen)
        TextView tvJifen;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
